package cn.com.mrzheng.web.server.impl;

import cn.com.mrzheng.web.entity.Post;
import cn.com.mrzheng.web.mapper.IPostMapper;
import cn.com.mrzheng.web.server.Base.BaseService;
import cn.com.mrzheng.web.server.interfaces.IPostServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Currency;
import java.util.List;

@Service
public class PostService implements IPostServer {
    @Autowired
    IPostMapper postdao;
    @Override
    public String add(Post post) {
        int i = postdao.add(post);
        if (i==1){
            return "添加文章成功！";
        } else
            return "添加文章失败！";
    }

    @Override
    public String delete(String id) {
        int i = postdao.delete(id);
        if (i==1){
            return "删除文章成功！";
        } else
            return "删除文章失败！";
    }

    @Override
    public String update(Post post) {
        int i = postdao.update(post);
        if (i==1){
            return "更新文章成功！";
        } else
            return "更新文章失败！";
    }

    @Override
    public Post findEntity(String id) {
        Post post = postdao.findByid(id);
        if ( post != null )
            return post;
        else
            return null;
    }

    @Override
    public List<Post> List(Integer CurrentPage, Integer PageSize) {
        List<Post> list = postdao.listBySort((CurrentPage-1)*PageSize, PageSize);
        return list;
    }

    @Override
    public List<Post> List() {
        List<Post> list = postdao.list();
        return list;
    }

    @Override
    public List<Post> listByAuthor(String Author, Integer CurrentPage, Integer PageSize) {
        List<Post> list = postdao.listByAuthor(Author,(CurrentPage-1)*PageSize, PageSize);
        return list;
    }
}
